// pages/winnerAddress/winnerAddress.js
import userService from '../../services/user'
import config from '../../config/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    userService.lotteryAddress(Number(options.lottery_id))
      .then(res => {
        if (res.resCode == config.Lottery.ResCode.Success) {
          this.setData({
            drawnUsers: res.data.drawnUsers
          })
        }
      })
      .catch(err => console.error(err));
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  /**
   * 复制中奖用户地址
   */
  copyAddress:function(){
    let copyStr = "";
    this.data.drawnUsers.forEach(drawnUser => {
      copyStr = copyStr + drawnUser.username + ":" + drawnUser.address.province_name + ' ' + drawnUser.address.city_name + ' ' + drawnUser.address.county_name + ' ' + drawnUser.address.detail_info + ' ' + drawnUser.address.tel_number+";\n";
    });
    wx.setClipboardData({
      data: copyStr,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功',
              icon: 'success'
            })
          }
        })
      }
    })
  }
})